#******************************************************************
#
# Copyright 2014 Samsung Electronics All Rights Reserved.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

import os
Import('env')

yaml_env = env.Clone()
src_dir = env.get('SRC_DIR')

yamlDir = os.path.join(src_dir, 'extlibs', 'yaml', 'yaml')

if not os.path.exists(yamlDir):
    msg = '''
*********************************** Error: ************************************
* Please download yaml using the following command:
*     $ git clone https://github.com/jbeder/yaml-cpp.git extlibs/yaml/yaml
*******************************************************************************
'''
    Exit(msg)

######################################################################
# Build flags
######################################################################
yaml_env.AppendUnique(CPPPATH=['yaml/src', 'yaml/include'])
yaml_env.AppendUnique(CXXFLAGS=['-std=c++0x', '-Wall', '-pthread'])
yaml_env.AppendUnique(CPPDEFINES=['LINUX'])
yaml_env.AppendUnique(LIBS=['pthread'])

# Remove -Werror build flag when building the 'YamlParser' library  it
# is external code. see IOT-2539
while '-Werror' in yaml_env['CCFLAGS']: yaml_env['CCFLAGS'].remove('-Werror')


yaml_env.AppendUnique(
    CXXFLAGS=['-O2', '-g', '-Wall', '-fmessage-length=0', '-std=c++0x'])

######################################################################
# Source files and Targets
######################################################################
yaml_src = [env.Glob('yaml/src/*.cpp'), env.Glob('yaml/src/contrib/*.cpp')]
yamlsdk = yaml_env.StaticLibrary('YamlParser', yaml_src)

yaml_env.InstallTarget(yamlsdk, 'libYaml')
